﻿
    <div class="container-fluid maindiv" style="margin-top: 20px" id="dvContent" ms-controller="LCSZ">

        <div class="row contentdv" style="margin-left:0px">
            <div class="col-xs-12 ">
                <div class="form-group">
                    <label>流程类型</label>
                    <select class="form-control" ms-change="xglx()" id="lclx">
                        <option value=-1>关闭流程</option>
                        <option value=0>自由流程</option>
                        <option value=1>固定流程</option>
                    </select>
                </div>
                <div class="form-group" ms-visible="modelData.ProcessType==-1">
                    <label class="text-info">关闭流程时新增数据不需要审批直接保存</label>
                </div>
                <div class="form-group" ms-visible="modelData.ProcessType==0">
                    <label>可选审核人</label>
                    <input type="text" ms-duplex="modelData.Alias" class="form-control szhl_getPeoples" style="display:none;" />
                </div>
                <div class="ft14 pt20" ms-visible="modelData.ProcessType==1">
                    <table class="table table-striped table-responsive table-hover table-bordered">
                        <thead>
                            <tr>
                                <th>节点步骤</th>
                                <th>节点名称</th>
                                <th>节点类型</th>
                                <th>节点处理人</th>
                                <th style="width:100px">是否可编辑</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ms-repeat-item="LCItemList">
                                <td>{{item.Taskorder}}</td>
                                <td>{{item.TaskName}}</td>
                                <td>{{GetNodeTypeName(item.NodeType)}}</td>
                                <td ms-click="SelRole(item)"> <a href="javascript:void(0)" class="btn-link">{{item.TaskAssInfo}}</a></td>
                                <td style="text-align:center">
                                    <div class="icheckbox_square-blue" ms-visible="!$first" ms-class-1="checked:item.isCanEdit" ms-click="ChangeCheck(item)">
                                        <!--<input type="checkbox" ms-duplex-checked="item.isCanEdit">-->
                                        <span class="iconfont icon-check ft12"></span>
                                    </div>
                                </td>
                                <td>
                                    <a class="cz-btn ft18 sc-color tip" data-toggle="tooltip" title="删除" ms-if="$last" ms-click="deljd(item,$event)">
                                        <i class="iconfont icon-shanchu"></i>
                                    </a>
                                </td>
                            </tr>
                        </tbody>
                        <tfoot>
                            <tr id="addwf" style=" border-bottom: 1px solid #ddd;">
                                <td></td>
                                <td><input type="text" class="form-control" ms-duplex="LCItem.TaskName" placeholder="节点名称"></td>
                                <td>
                                    <select class="form-control" ms-duplex="LCItem.NodeType">
                                        <option value="NODE">中间节点</option>
                                        <option value="END">结束节点</option>
                                    </select>
                                </td>
                                <td>
                                    <input type="text" class="form-control" ms-click="SelRole(LCItem)" ms-duplex="LCItem.TaskAssInfo" placeholder="节点处理人">
                                </td>
                                <td style="text-align:center">
                                    <div class="icheckbox_square-blue" id="ckb" ms-click="ChangeCheck(LCItem)" ms-class-1="checked:LCItem.isCanEdit">
                                        <!--<input type="checkbox" ms-duplex-checked="LCItem.isCanEdit">-->
                                        <span class="iconfont icon-check ft12"></span>
                                    </div>
                                </td>
                                <td>
                                    <a class="cz-btn ft18 tip" data-toggle="tooltip" title="添加" ms-click="addjd()">
                                        <i class="iconfont icon-jiahao ft14"></i>
                                    </a>
                                </td>
                            </tr>
                        </tfoot>
                    </table>
                </div>

                <div class="form-group">
                    <label>默认抄送人</label>
                    <input type="text" ms-duplex="modelData.ChaoSongUser" class="form-control szhl_getPeoples" style="display:none;" />
                </div>
                <div style="text-align:center">
                    <button type="button" class="btn btn-info btn-lg" ms-click="AddLCSZ()"><i class="iconfont icon-jiahao ft12 mr5"></i>保存数据</button>
                </div>

            </div>
        </div>
    </div>


    <script>
        var processId = model.SelModel.PDID;
        var tempindex = avalon.define({
            $id: "LCSZ",
            modelData: {},
            nowmodel:  model.SelModel,
            LCItem: { TaskName: "提出申请", Taskorder: "", AssignedRole: "", TaskAssInfo: "", NodeType: "NODE", ProcessDefinitionID: processId, isSJ: "0", TDCODE: "", isCanEdit: false },
            LCItemList: [{ TaskName: "提出申请", Taskorder: "1", AssignedRole: "", TaskAssInfo: "", NodeType: "START", ProcessDefinitionID: processId, isSJ: "0", TDCODE: processId + "-1", isCanEdit: false }],//固定流程数据
            addjd: function () {
                if (tempindex.LCItem.TaskName == "") {
                     ComFunJS.winwarning("请输入节点步骤");
                    return;
                }
                if (tempindex.LCItem.TaskAssInfo == "") {
                     ComFunJS.winwarning("请选择节点处理人");
                    return;
                }
                if (tempindex.LCItem.NodeType == "END") {
                    $("#addwf").css("display", "none")
                }
                if ($("#ckb").hasClass("checked")) {
                    tempindex.LCItem.isCanEdit = true;
                }
                else {
                    tempindex.LCItem.isCanEdit = false;
                }
                tempindex.LCItem.Taskorder = tempindex.LCItemList.size() + 1;
                tempindex.LCItem.TDCODE = tempindex.LCItem.ProcessDefinitionID + "-" + tempindex.LCItem.Taskorder;
                tempindex.LCItemList.push($.extend({}, tempindex.LCItem.$model));
                $("#ckb").removeClass("checked");
                tempindex.LCItem.isCanEdit = false;
                tempindex.LCItem.Taskorder = "";
                tempindex.LCItem.TaskName = "";
                tempindex.LCItem.TDCODE = "";
                tempindex.LCItem.TaskAssInfo = "";

            },
            deljd: function (item) {
                if (item.NodeType == "END") {
                    $("#addwf").css("display", "")
                }
                tempindex.LCItemList.remove(item);
            },
            AddLCSZ: function () {
                $("tbody .icheckbox_square-blue").each(function (inx) {
                    if ($(this).hasClass("checked")) {
                        tempindex.LCItemList[inx].isCanEdit = true;
                    }
                    else {
                        tempindex.LCItemList[inx].isCanEdit = false;
                    }
                })
                var modelValue;
                var modelValue2;
                modelValue = JSON.stringify(tempindex.modelData.$model)
                modelValue2 = tempindex.LCItemList.size() > 0 ? JSON.stringify(tempindex.LCItemList.$model) : "";
                var qymodelId = "";
                if (!tempindex.nowmodel.PDID && tempindex.nowmodel.QYModelId) {
                    qymodelId = tempindex.nowmodel.QYModelId
                }
                if (tempindex.LCItemList[tempindex.LCItemList.size() - 1].NodeType != "END" && tempindex.modelData.ProcessType == 1) {
                    ComFunJS.winwarning("没有结束节点,不能保存不完整的流程");
                } else {
                    $.post("/API/VIEWAPI.ashx", { Action: "LCSP_ADDPROCESS", P1: modelValue, P2: modelValue2, qymodelId: qymodelId, modelCode: tempindex.nowmodel.modelCode },
              function (result) {
                  var err = JSON.parse(result);
                  if (err.ErrorMsg != "") {
                      
                      ComFunJS.winwarning(err.ErrorMsg);
                  } else {
                      tempindex.modelData = err.Result;
                      model.SelModel.PDID = err.Result.ID;
                      ComFunJS.winsuccess("设置成功");
                  }
              });
                }
            }, SelRole: function (item) {
                if (item.NodeType == "START") {
                    return;
                }
                 ComFunJS.winbtnwin("/ViewV5/Base/LCSZSelect.html?rytype=" + item.isSJ + "&&checkvalue=" + item.AssignedRole, "选择角色", 500, 400, {}, function (layero, index) {
                    var frameid = $("iframe", $(layero)).attr('id');
                    var data = ComFunJS.isIE() ? window.frames[frameid].getlcry() : window.frames[frameid].contentWindow.getlcry();

                    item.AssignedRole = data.RoleCode;
                    item.TaskAssInfo = data.LCName;
                    item.isSJ = data.LCtype;
                     layer.close(index)
                })
            }
            , GetNodeTypeName: function (nodeType) {
                var nodeName = "";
                if (nodeType == "START") {
                    nodeName = "开始节点";
                }
                if (nodeType == "NODE") {
                    nodeName = "中间节点";
                }
                if (nodeType == "END") {
                    nodeName = "结束节点";
                }
                return nodeName;
            },
            InitWigetData: function () {
                if (processId) {
                    //编辑加载数据
                    $.getJSON('/API/VIEWAPI.ashx?Action=LCSP_GETPROCESSBYID', { P1: processId }, function (resultData) {
                        if (resultData.ErrorMsg == "") {
                            tempindex.modelData = resultData.Result;
                            if (!tempindex.modelData.ProcessType) {
                                tempindex.modelData.ProcessType = -1;
                            }
                            $("#lclx").val(tempindex.modelData.ProcessType);
                            setTimeout("ComFunJS.initForm()", 500);
                        }
                    })
                    //编辑加载数据
                    $.getJSON('/API/VIEWAPI.ashx?Action=LCSP_GETTDLIST', { P1: processId }, function (resultData) {
                        if (resultData.ErrorMsg == "") {
                            if (resultData.Result.length > 0) {
                                tempindex.LCItemList = resultData.Result;
                                tempindex.LCItemList.forEach(function (val) {
                                    if (val.NodeType == "END") {
                                        $("#addwf").css("display", "none")
                                    }
                                    val.isCanEdit = val.isCanEdit.toLowerCase() == "true";
                                })
                            }
                        }
                    })
                } else {
                    tempindex.modelData = { ID: 0, "ProcessName": "", "Alias": "", "ProcessType": -1, "isTemp": 0, "ChaoSongUser": "" };
                    if (tempindex.nowmodel) {
                        tempindex.modelData.ProcessName = tempindex.nowmodel.ModelName;
                    }
                    $("#lclx").val(tempindex.modelData.ProcessType);
                    ComFunJS.initForm();
                }
            },
            xglx: function () {
                tempindex.modelData.ProcessType = $("#lclx").val() * 1;
            },ChangeCheck:function(lcitem){
                lcitem.isCanEdit = !lcitem.isCanEdit;
            }
        })
        //# sourceURL=LCSZ.js;
    </script>

